<?php
mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
mysql_select_db("sapmenet_users");

	$FirstName=$_POST['FirstName'];
	$FirstName=htmlspecialchars($FirstName);
	$FirstName=mysql_real_escape_string($FirstName);
	$LastName=$_POST['LastName'];
	$LastName=htmlspecialchars($LastName);
	$LastName=mysql_real_escape_string($LastName);
	$password=$_POST['password'];
	$repassword=$_POST['rePassword'];
	$email=$_POST['email'];
	$email=htmlspecialchars($email);
	$email=mysql_real_escape_string($email);
	$reEmail=$_POST['reEmail'];
	$reEmail=htmlspecialchars($reEmail);
	$reEmail=mysql_real_escape_string($reEmail);
	$sex=$_POST['sex'];
	$theDate=$_POST['date'];
	$password=md5($password);
	$password=$password.'tapak';
	$password=md5($password);
	$repassword=md5($repassword);
	$repassword=$repassword.'tapak';
	$repassword=md5($repassword);
	
	
	/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email 
address format and the domain exists.
*/
function validEmail($email)
{
   $isValid = true;
   $atIndex = strrpos($email, "@");
   if (is_bool($atIndex) && !$atIndex)
   {
      $isValid = false;
   }
   else
   {
      $domain = substr($email, $atIndex+1);
      $local = substr($email, 0, $atIndex);
      $localLen = strlen($local);
      $domainLen = strlen($domain);
      if ($localLen < 1 || $localLen > 64)
      {
         // local part length exceeded
         $isValid = false;
      }
      else if ($domainLen < 1 || $domainLen > 255)
      {
         // domain part length exceeded
         $isValid = false;
      }
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
      {
         // local part starts or ends with '.'
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $local))
      {
         // local part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
      {
         // character not valid in domain part
         $isValid = false;
      }
      else if (preg_match('/\\.\\./', $domain))
      {
         // domain part has two consecutive dots
         $isValid = false;
      }
      else if (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
      {
         // character not valid in local part unless 
         // local part is quoted
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
             str_replace("\\\\","",$local)))
         {
            $isValid = false;
         }
      }
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
      {
         // domain not found in DNS
         $isValid = false;
      }
   }
   return $isValid;
}
		if (validEmail($email) && (!ereg('[^A-Za-z]', $FirstName))  &&(!ereg('[^A-Za-z]', $LastName)) && ($password==$repassword) && ($email==$reEmail))
		{
	
		$insert="INSERT INTO users (FirstName, LastName, password, email, Sex, birthdate)VALUES ('".$FirstName."', '".$LastName."', '".$password."', '".$email."', '".$sex."', '".$theDate."')"; 
		$result=mysql_query($insert) or die ("There are user with the same e-mail!");
		$id=mysql_query("SELECT ID FROM users WHERE email LIKE '".$email."'" );
		$id=mysql_result($id, 0);
		$to=$email;
		$subject ='Successful registration';
		$message ='You registered successfull in www.sapMe.net'. "\r\n" .
		 "Visit this website http://sapme.net?id=$id to activate your profile!";
		$headers ='From: admins@sapme.net';
		mail($to, $subject, $message, $headers);
		$today = date("Y-m-d");   
		$up="UPDATE  `sapmenet_users`.`users` SET  `registered` = '".$today."' WHERE email LIKE '".$email."'";
		mysql_query($up);
		chdir(Framework);
		chdir(pictures);
		mkdir($id);
		if(true)
		{
			header('Location: index.php?ok=Check your e-mail to activate your profile!');
		}
		}
		else 
		{
			echo("Incorrect information!");
		}
?>